package com.example.bookkeepingelf.base.listener;

import android.app.Activity;
import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.room.RoomDatabase;

import com.example.bookkeepingelf.business.database.AppDatabase;

/**
 * 抽象的点击事件监听器
 * @param
 */
public abstract class AbstractActivityViewListener<T extends Activity> implements View.OnClickListener{

    /**
     * 宿主Activity
     */
    private T hostActivity;

    /**
     * 上下文
     */
    private Context context;

    private RoomDatabase database;


    /**
     * 构造函数
     * @param hostActivity 宿主Activity
     */
    public AbstractActivityViewListener(@NonNull T hostActivity) {
        this.hostActivity = hostActivity;
        this.context = hostActivity.getApplicationContext();

        // 初始化数据库
        this.database = AppDatabase.getDatabase(hostActivity);
        this.initialization(this.database);
    }

    protected void initialization(RoomDatabase database){}


    /**
     * 获取宿主Activity
     * @return
     */
    public T getHostActivity() {
        return hostActivity;
    }

    public void setHostActivity(T hostActivity) {
        this.hostActivity = hostActivity;
    }

    /**
     * 获取上下文
     * @return
     */
    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }
}
